﻿using System;
using System.Configuration;
using System.Globalization;
using System.Threading;
using System.Windows.Forms;

namespace Alerter
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Thread.CurrentThread.CurrentUICulture = new CultureInfo("pt-PT");
            var licenseKey = ConfigurationManager.AppSettings["LicenseKey"];
            var controller = new Controller();
            controller.SetLogFile();
            controller.SetVersion();
            if (!E4RPLicense.License.Validate(E4RPTools.Product.Alerter.ToString(), (long)E4RPTools.Product.Alerter, controller.Version, licenseKey))
                return;
            var user = ConfigurationManager.AppSettings["User"];
            var password = ConfigurationManager.AppSettings["Password"];
            if (!controller.Login(user, password))
                return;
            controller.ComPort = Convert.ToInt32(ConfigurationManager.AppSettings["PortaCOM"]);
            controller.BaudRate = Convert.ToInt32(ConfigurationManager.AppSettings["Frequencia"]);
            controller.Timeout = Convert.ToInt32(ConfigurationManager.AppSettings["Timeout"]);
            controller.PhoneConnected();
            var main = new MainRibbonForm { Controller = controller };
            Application.Run(main);             
        }
    }
}
